/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.bangong.fwclxxl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import me.zhengjie.modules.bangong.fwclxxl.domain.Fwcljbqk;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.bangong.fwclxxl.service.FwcljbqkService;
import me.zhengjie.modules.bangong.fwclxxl.domain.dto.FwcljbqkQueryCriteria;
import me.zhengjie.modules.bangong.fwclxxl.mapper.FwcljbqkMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author Houger
* @date 2025-03-09
**/
@Service
@RequiredArgsConstructor
public class FwcljbqkServiceImpl extends ServiceImpl<FwcljbqkMapper, Fwcljbqk> implements FwcljbqkService {

    private final FwcljbqkMapper fwcljbqkMapper;

    @Override
    public PageResult<Fwcljbqk> queryAll(FwcljbqkQueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(fwcljbqkMapper.findAll(criteria, page));
    }

    @Override
    public List<Fwcljbqk> queryAll(FwcljbqkQueryCriteria criteria){
        return fwcljbqkMapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(Fwcljbqk resources) {
        fwcljbqkMapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Fwcljbqk resources) {
        Fwcljbqk fwcljbqk = getById(resources.getColumnId());
        fwcljbqk.copy(resources);
        fwcljbqkMapper.update(fwcljbqk,new QueryWrapper<>());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        fwcljbqkMapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<Fwcljbqk> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (Fwcljbqk fwcljbqk : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("拟稿人职工号", fwcljbqk.getNgrzgh());
            map.put("拟稿日期", fwcljbqk.getNgrq());
            map.put("签发人职工号", fwcljbqk.getQfrzgh());
            map.put("签发日期", fwcljbqk.getQfrq());
            map.put("发送范围", fwcljbqk.getFsfw());
            map.put("发送方式码", fwcljbqk.getFsfsm());
            map.put("登记人职工号", fwcljbqk.getDjrzgh());
            map.put("登记日期", fwcljbqk.getDjrq());
            map.put("发文件数", fwcljbqk.getFwjs());
            map.put("发文日期", fwcljbqk.getFwrq());
            map.put("处理情况", fwcljbqk.getClqk());
            map.put("打字人职工号", fwcljbqk.getDzrzgh());
            map.put("校对人职工号", fwcljbqk.getJdrzgh());
            map.put("封装方式码", fwcljbqk.getFzfsm());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}